import java.util.Scanner;
/*
题目 : 将 num 任意进制转化
 */
public class TurnDigit {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int num = in.nextInt();
        int base = in.nextInt();
        StringBuilder src = new StringBuilder();
        if (num == 0) {
            src.append('0');
        } else {
            boolean flg = num >= 0;
            if (!flg)    num *= -1;
            while (num != 0) {
                int remain = num % base;
                char temp = remain < 10 ? (char) (remain + '0') : (char) (remain - 10 + 'A');
                src.append(temp);
                num /= base;
            }
            if (!flg) {
                src.append('-');
            }
        }
        System.out.println(src.reverse().toString());
    }
}
